/*
 * @Author: geyulan 18500325526@163.com
 * @Date: 2020-04-26 10:56:12
 * @LastEditors: geyulan 18500325526@163.com
 * @LastEditTime: 2023-12-12 16:42:54
 * @FilePath: /coupon-laxin/src/api/ajax.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import axios from 'axios'
import Vue from 'vue'
import common from '../mixin/common.js'
// import qs from 'qs'
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
// axios.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'
// axios.defaults.headers.get['Content-Type'] = 'application/x-www-form-urlencoded'
axios.interceptors.request.use(function (config) {
  let {getCookie} = common.methods
  config.headers['Access-Token'] = getCookie('Access-Token')
  config.headers['Is-Refresh-Token'] = getCookie('Is-Refresh-Token')
  config.headers['Source-Type'] = getCookie('Source-Type')
  config.headers['basic-zd-context-BusinessType'] = getCookie('basic-zd-context-BusinessType')
  config.headers['basic-zd-context-MemberCardNo'] = getCookie('basic-zd-context-MemberCardNo')
  config.headers['basic-zd-context-MemberId'] = getCookie('basic-zd-context-MemberId')
  return config
})
Vue.prototype.$axios = axios
const fetch = ({ url, body, type, headers }) => {
  if (type === 'POST') {
    // return axios.post(url, qs.stringify(body), { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } })
    return axios.post(url, body, { headers: { 'Content-Type': 'application/json;charset=UTF-8' } })
  } else {
    if (headers) {
      return axios.get(url, { params: body, headers: headers })
    } else {
      return axios.get(url, { params: body })
    }
  }
}
export default fetch
